
var morgan = require('morgan');
// 日志分割
var fileStreamRotator = require('file-stream-rotator')
var moment = require('moment')
var path = require('path');
var fs = require('fs')

var logDir = path.join(__dirname, '../log')
fs.existsSync(logDir) || fs.mkdirSync(logDir)

var accessLogStream = fileStreamRotator.getStream({
    date_format: 'YYYYMMDD',
    filename: path.join(logDir, 'access-%DATE%.log'),
    frequency: 'daily',
    verbose: false
})
// 设置log格式
morgan.token('datetime', function (req, res){
    return moment().format('YYYY/MM/DD HH:mm:ss')
})
morgan.token('query', function (req, res){
})
morgan.token('params', function (req, res){
})
morgan.format('log', '[log] :datetime :method :url :query :params :status :response-time ms')

module.exports = morgan('log',{stream: accessLogStream})

